<?php
namespace Admin\Controller;
use Think\Controller;
class FinanceController extends BaseController{
    public function recharge(){
        $m=M('Recharge');
		$keywords=I('get.keywords');     
		$selval=I('get.selval');     
		$p=I('p')?I('p'):1;
		$listrows=20;
		$firstrow=($p-1)*$listrows;
        if(!empty($keywords)){
			if($selval=='1'){
				$map['member_name'] = array('like','%'.$keywords.'%');
			}
        }
		$count=$m->where($map)->count();
		$list=$m->where($map)->limit($firstrow.','.$listrows)->order('id desc')->select();

		$Page       = new \Think\Page($count,$listrows);// 实例化分页类 传入总记录数和每页显示的记录数(25)
		$show       = $Page->show();// 分页显示输出
		
		
		
		$this->assign("count",$count);
		$this->assign("list",$list);
		$this->assign('page',$show);// 赋值分页输出
		$this->display();
    }
	//添加
	function add_recharges(){
			$m=M('Recharge');
			$param = I('param.','','trim');
			$Member=M('Member');
			$member_info=$Member->where(array('id'=>$param['member_id']))->find();
			$param['member_name']=$member_info['name'];
			$param['add_time']=time();
			$res=$m->add($param);
			if($res){
				$data_charge['money']=array('exp','money+'.$param['money']);
				$Member->where(array('id'=>$param['member_id']))->save($data_charge);
				$this->success('添加成功');
			}
	}
	//更新
	function add_recharge(){

		$Member=M('Member');
		$member_list=$Member->where(array('status'=>1))->select();
		
		$this->assign("member_list",$member_list);
		if(IS_POST){
			$m=M('Recharge');
			$param = I('param.','','trim');
			$Member=M('Member');
			$member_info=$Member->where(array('id'=>$param['member_id']))->find();
			$param['member_name']=$member_info['name'];
			$param['update_time'] = time();
			$id=$param['id'];
			$res=$m->where(array('id'=>$id))->save($param);
			
			if($res!==false){
				$this->success('更新成功');
			}
		}else{
			$this->display();
		}
	}
	//编辑
	function edit_recharge(){
		$Member=M('Member');
		$member_list=$Member->where(array('status'=>1))->select();
		
		$this->assign("member_list",$member_list);
		$id=trim(I('id'));
		$m=M('Recharge');
		$detail=$m->where(array('id'=>$id))->find();
		$this->assign('detail',$detail);
		$this->display();
	}
	//删除
	function del_recharge(){
		$id=trim(I('id'));
		$m=M('Recharge');
		$map['id']=$id;
		$status=$m->where($map)->delete();

		if($status!==false){
            echo "y";
        }else{
            echo "操作失败";
        }
	}
	
	
}